<template>
  <div>
    <el-dropdown>
      <el-icon><MoreFilled /></el-icon><arrow-down />
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item
            :icon="WarnTriangleFilled"
            v-if="myId != propsId.userId"
            @click="reportOther"
          >
            举报
          </el-dropdown-item>
          <el-dropdown-item :icon="Delete" v-else @click="deleteDongtai"
            >删除</el-dropdown-item
          >
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>
<script setup>
import { Delete, WarnTriangleFilled, MoreFilled } from '@element-plus/icons-vue'
import { ref, defineProps } from 'vue'
import axios from 'axios'
const propsId = defineProps(['userId', 'dynamicId', 'userName'])
const myId = ref(localStorage.getItem('userSelfId'))

console.log(myId.value + propsId.userId)
function reportOther() {
  axios({
    url: 'http://localhost:8080/dExamine/report',
    method: 'post',
    contentType: 'application/json',
    headers: {
      token: localStorage.getItem('token')
    },
    data: {
      dynamicId: propsId.dynamicId,
      badUserId: propsId.userId,
      badUser: propsId.userName
    }
  }).then(function (res) {
    alert(JSON.stringify(res.data))
  })
}

function deleteDongtai() {
  axios({
    url: 'http://localhost:8080/dynamic/delete',
    method: 'delete',
    contentType: 'application/json',
    headers: {
      token: localStorage.getItem('token')
    },
    data: {
      dynamicId: propsId.dynamicId
    }
  }).then(function (res) {
    alert(JSON.stringify(res.data))
  })
}
</script>
